package dryven.view.engine.expression;

import dryven.codegen.asm.MethodBuilder;
import dryven.reflection.TypeRef;
import dryven.view.ViewDataDictionary;

public class CompiledViewExpression {
	
	private Iterable<ExpressionNode> _nodes;
	
	public CompiledViewExpression(Iterable<ExpressionNode> nodes) {
		super();
		_nodes = nodes;
	}

	public Iterable<ExpressionNode> getNodes() {
		return _nodes;
	}
	
	public Iterable<ExpressionNode> getSuggestions() {
		ExpressionNode lastNode = null;
		for (ExpressionNode node : _nodes) {
			lastNode = node;
		}
		return lastNode.getChildren();
	}
	
	public void writeInstructions(MethodBuilder builder) {
		
	}
	
	public TypeRef getExpressionType() {
		ExpressionNode lastNode = null;
		for (ExpressionNode node : _nodes) {
			lastNode = node;
		}
		return lastNode.getType();
	}
	
	public Object evaluate(ViewDataDictionary viewdata) {
		Object value = viewdata;
		for (ExpressionNode node : _nodes) {
			value = node.evaluate(value);
		}
		return value;
	}
}
